require "Common/define"
require "Logic/Config"
require "Net/send_Msg"
require "Logic/NewPlayerActiveManager"
require "proto/timelimit/share/message/ReqShareActivityInfoMessage"
require "proto/timelimit/share/message/ReqInviteCodeAwardMessage"
require "proto/timelimit/share/message/ReqScoreAwardMessage"
require "proto/timelimit/share/message/ReqRecvinviteAwardMessage"
require "proto/timelimit/share/message/ReqRecvShareTaskAwardMessage"


newPlayerActiveHandler = newPlayerActiveHandler or {}

--请求个人分享信息活动
function newPlayerActiveHandler.ReqShareActivityInfo(activityId)
    local req = ReqShareActivityInfoMessage.New()
    req.activityId = 18001
    sendReqMessage(req)
end

function newPlayerActiveHandler.ResShareActivityInfo(msg)
    if msg.state == 0 then
        logicMgr.NewPlayerActiveManager.SaveNewPlayerInfo(msg)
    end
end

--请求领取积分奖励
function newPlayerActiveHandler.ReqScoreAward(activityId, scoreAwardId)
    local req = ReqScoreAwardMessage.New()
    req.activityId = activityId
    req.scoreAwardId = scoreAwardId
    sendReqMessage(req)
end

function newPlayerActiveHandler.ResScoreAward(msg)
    if msg.state == 0 then
        logicMgr.NewPlayerActiveManager.SetBoxData(msg.scoreAwardId, 2)
        showUI(PanelNames.UICommonItemGet,nil,nil,2,msg.items)
        FireEvent(Config.EventType.NewPlayerRefresh)
        FireEvent(Config.EventType.Fresh_Active)
    end
end

--请求领取邀请码奖励
function newPlayerActiveHandler.ReqInviteCodeAward(activityId,inviteCode)
    local req = ReqInviteCodeAwardMessage.New()
    req.activityId = activityId
    req.inviteCode = inviteCode
    sendReqMessage(req)
end

function newPlayerActiveHandler.ResInviteCodeAward(msg)
    if msg.state == 0 then
        showUI(PanelNames.UICommonItemGet,nil,nil,2,msg.items)
        local playerData = logicMgr.NewPlayerActiveManager.GetPlayerSelfData()
        playerData.useCodeCount = 1
        local _,_,taskData = logicMgr.NewPlayerActiveManager.GetBoxAndTaskData()
        for _,v in pairs(taskData) do
            v.state = 1
        end
        FireEvent(Config.EventType.NewPlayerRefresh)
        FireEvent(Config.EventType.Fresh_Active)
    end
end

--请求领任务奖励
function newPlayerActiveHandler.ReqRecvShareTaskAward(activityId,taskId)
    local req = ReqRecvShareTaskAwardMessage.New()
    req.activityId = activityId
    req.taskId = taskId
    sendReqMessage(req)
end

--请求领任务奖励
function newPlayerActiveHandler.ResRecvShareTaskAward(msg)
    if msg.state == 0 then
        local type = logicMgr.NewPlayerActiveManager.GetTypeByTaskId(msg.taskId)
        if type > 0 then
            if type == 2201 then
                logicMgr.NewPlayerActiveManager.SetTaskData(msg.taskId, 3)
                FireEvent(Config.EventType.NewPlayerRefreshInviteePage)
            elseif type == 2202 then
                logicMgr.NewPlayerActiveManager.SetExtraBoxData(msg.taskId, 2)
                FireEvent(Config.EventType.NewPlayerRefresh)
            end
        end
        showUI(PanelNames.UICommonItemGet,nil,nil,2,msg.items)
        FireEvent(Config.EventType.Fresh_Active)
    end
end